<?
    /* -*- Mode: PHP5; tab-width: 4; indent-tabs-mode: nil; basic-offset: 4 -*- */
    
    /*********************************************************
    *            --== InArch ==--
    *
    * Ajax Abstraction Layer
    *
    * @author Kulikov Alexey <a.kulikov@gmail.com>
    * @version n/a
    * @since 02.09.2005
    * @copyright essentialmind.com 2005
    *
    *********************************************************/

    /***
    * Abstract Class cronJob
    ****
    * This is a signature class for all the possible cron jobs 
    * that can take place
    ****
    * @package cron
    * @author A Kulikov <a.kulikov@gmail.com>
    * @version n/a
    * @since 02.09.2005
    * @copyright essentialmind.com 2005
    ***/
    class cronJobSitemap extends cronJob{
            
        public function process(){
            $folders = $this->db->getAll("SELECT title, modified, get_path(nodeid) AS url FROM objectmap LEFT JOIN structure ON objectmap.nodeid = structure.id WHERE published IS NOT NULL");
            $pages   = $this->db->getAll("SELECT title, modified, get_path(nodeid)||pagemap.pageurl||'.html' AS url FROM pagemap LEFT JOIN structure ON pagemap.nodeid = structure.id WHERE published IS NOT NULL");                        
            
            
            header ("content-type: text/xml");
            print '<?xml version="1.0" encoding="UTF-8"?>';
            print '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">';
            foreach($folders as $folder){
                print '<url>
                          <loc>'.$GLOBALS['_CONFIG']['server_root'].$folder['url'].'</loc>
                          <lastmod>'.date('Y-m-d', strtotime($folder['modified'])).'</lastmod>
                          <changefreq>weekly</changefreq>
                          <priority>0.7</priority>
                        </url>';
            }
            
            foreach($pages as $page){
                print '<url>
                          <loc>'.$GLOBALS['_CONFIG']['server_root'].$page['url'].'</loc>
                          <lastmod>'.date('Y-m-d', strtotime($page['modified'])).'</lastmod>
                          <changefreq>weekly</changefreq>
                          <priority>1.0</priority>
                        </url>';
            }
            print '</urlset>';
        }
    }
